from django.contrib import admin
from django.utils.html import format_html

from .models import Coupon


# Register your models here.

@admin.register(Coupon)
class CouponAdmin(admin.ModelAdmin):
    list_display = ['code', 'valid_from', 'valid_to', 'discount', 'active', 'operator']
    list_filter = ['active', 'valid_from', 'valid_to']
    search_fields = ['code']

    def operator(self, obj):
        return format_html(f'<a href="/admin/coupons/coupon/{obj.id}/change/">编辑</a>')

    operator.short_description = '操作'
